<?php

namespace app\cps\controller;

use think\facade\Request;
use app\common\Common;
use app\common\Error;
use think\facade\Db;
use think\facade\Cache;
use think\facade\Log;
use think\facade\Queue;
use app\cps\service\TencentService;

// 腾讯投放接入
class Tencent extends Base
{
    private $service;

    public function __construct(TencentService $service)
    {
        parent::__construct();
        $this->service = $service;
    }

    // 首次获取腾讯广告平台accessToken
    public function getTencentAdAccessToken()
    {
        $params = Request::param();
    }

    // 首次获取腾讯广告平台code
    public function getTencentAdCode()
    {
        // 请求地址：https://developers.e.qq.com/oauth/authorize?client_id=1112016965&redirect_uri=https://ht.sybyn.top/cps/tencent/getTencentAdCode&state=&account_type=ACCOUNT_TYPE_QQ
        $params = Request::param();
        $this->service->getTencentAccessTokenByCode($params['authorization_code']);
    }

    // 渲染腾讯数据源id列表页面
    public function index()
    {
        return view();
    }

    // 腾讯数据源id列表
    public function list()
    {
        $params = Request::param();
        $data = $this->service->getTencentDataSourceIdList($params, $this->getUserInfo());

        return Common::success($data);
    }

    // 渲染腾讯创建数据源id页面
    public function info()
    {
        return view();
    }

    // 腾讯创建数据源id
    public function createDataSource()
    {
        $params = Request::param();

        try {
            validate(\app\cps\validate\Link::class)->scene('create_tencent_data_source_id')->check($params);
        } catch (\Exception $e) {
            return Common::fail($e->getError());
        }

        $data = $this->service->createTencentDataSourceId($params, $this->getUserInfo());

        if (!empty($data['message'])) {
            return Common::fail($data['message']);
        }

        return Common::success();
    }
}